use std::io;
use std::cmp::Ordering;
use rand::Rng;

fn main() {
    let r = rand::thread_rng().gen_range(1, 101);
    //println!("随机数是：{}", r);

    loop{
        let mut guess = String::new();
        println!("请输入数字：");
        io::stdin().read_line(&mut guess).expect("输入错误");

        //类型转换
        let guess: u32 = match guess.trim().parse(){
            Ok(num) => num,
            Err(_) => continue
        };

        //分支
        match guess.cmp(&r){
            Ordering::Less => println!("太小了"),
            Ordering::Greater => println!("太大了"),
            Ordering::Equal => {
                println!("猜对了");
                break;
            }
        }
    }
}
